<template>
  <el-dialog v-model="centerDialogVisible" fullscreen :show-close="false" custom-class="logindialog" width="100%"
    center>
    <div class="closerank" @click="close">
      <strong></strong>
      <h3>{{ $t("language.Terouro.name") }}</h3>
      <span>
        <el-icon color="#b5b6c8" size="16">
          <Close />
        </el-icon>
      </span>
    </div>
    <div id="Terouro">
      <main>
        <AppSkeleton :loading="loading">
          <template #ske>
            <div style="
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                justify-content: flex-start;
                align-items: center;
              ">
              <el-skeleton-item variant="image" style="width: 100%; height: 180px" />
              <div style="width: 100%; display: flex; margin-top: 20px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 20px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="width: 100%; display: flex; margin-top: 10px">
                <el-skeleton-item variant="text" style="width: 70%; height: 20px; margin-right: 20px" />
                <el-skeleton-item variant="h3" style="width: 30%; height: 20px" />
              </div>
              <div style="
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  margin-top: 50px;
                ">
                <el-skeleton-item variant="image" style="width: 43px; height: 43px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
                <el-skeleton-item variant="image" style="width: 43px; height: 43px; margin-left: 30px" />
              </div>
              <div style="
                  width: 100%;
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  margin-top: 20px;
                ">
                <el-skeleton-item variant="h3" style="width: 50%; height: 20px" />
              </div>
              <el-skeleton-item variant="text" style="width: 100%; height: 40px; margin-top: 20px" />

              <el-skeleton-item variant="text" style="width: 100%; height: 40px; margin-top: 20px" />
            </div>
          </template>
          <template #main>
            <NuxtImg src="/img/banner1.png" alt="" />
            <ul v-if="shareinfo.yesterdayData.registerCount != null">
              <li>
                <span>{{ $t('language.Terouro.yesterday.Registr') }}</span>
                <span>{{ shareinfo.yesterdayData.registerCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.yesterday.level') }}</span>
                <span>{{ shareinfo.yesterdayData.firstRechargeCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.yesterday.record') }}</span>
                <span>{{ shareinfo.yesterdayData.bonus }}</span>
              </li>
            </ul>
            <ul>
              <li>
                <span>{{ $t('language.Terouro.today.Registr') }}</span>
                <span>{{ shareinfo.todayData.registerCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.today.level') }}</span>
                <span>{{ shareinfo.todayData.firstRechargeCount }}</span>
              </li>
              <li>
                <span>{{ $t('language.Terouro.today.record') }}</span>
                <span>{{ shareinfo.todayData.bonus }}</span>
              </li>
            </ul>
            <div class="img">
              <NuxtImg v-for="(item, index) in imglist" @click="item.callback" :key="index" :src="item.img" alt="" />
            </div>
            <h3>{{ $t('language.Terouro.title') }}</h3>
            <dl>
              <dd>
                <span>{{ $t('language.Terouro.link1') }}</span>
                <div>
                  <span>{{ ip + "?gameID=" + info.gameID }}</span>
                  <el-button class="confirm" @click="copyToClipboard(ip)">{{
    $t("language.info.copy")
  }}</el-button>
                </div>
              </dd>
              <!-- v-if="Invite.code != ''" -->
              <dd>
                <span>{{ $t('language.Terouro.link2') }}</span>
                <div>
                  <span>{{ Invite.code }}</span>
                  <el-button @click="copyToClipboard(Invite.code)" class="confirm">{{
    $t("language.info.copy")
                    }}</el-button>
                </div>
              </dd>
            </dl>
          </template>
        </AppSkeleton>
      </main>
    </div>
  </el-dialog>
</template>
<script setup lang="ts">
import { Close } from '@element-plus/icons-vue'
import { reactive, shallowRef, nextTick, onBeforeMount, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
let store = useStore()
const { t } = useI18n();
let centerDialogVisible = computed<boolean>(() => store.terouro);
let loading = shallowRef<boolean>(false);
// 复制
let copyToClipboard = (text: string | number | null | undefined) => {
  let tmpTextField: any = document.createElement("textarea");
  tmpTextField.textContent = text;
  tmpTextField.setAttribute("style", "position:absolute; right:200%;");
  document.body.appendChild(tmpTextField);
  tmpTextField.select();
  tmpTextField.setSelectionRange(0, 99999); /*For mobile devices*/
  document.execCommand("copy");
  ElMessage({
    message: t("language.commontips.copysuccess"),
    type: "success",
    duration: 1000,
  });
}
let info: any = computed<any>(() => store.userinfo);
// const { proxy } = getCurrentInstance();
let shareinfo: any = reactive({
  todayData: { registerCount: 0, firstRechargeCount: 0, bonus: 0 },
  yesterdayData: { registerCount: 0, firstRechargeCount: 0, bonus: 0 }
})
let Invite: any = reactive({
  code: "",
  registerCount: 0
})
// 获取ip地址
let ip = shallowRef<null | undefined | string | number>(null)
onBeforeMount(() => {
  ip.value = window.location.href
})
//数据初始化
let initData = async () => {
  // 获取推广信息
  await nextTick()
  useAllData('InviteData', `/Activity/v1.0/InviteData`, { id: info.value.gameID }).then(({ data }: { data: any }) => {

    for (let key in data.value.data) {
      shareinfo[key] = data.value.data[key]
    }

  })
  // 获取宝箱信息
  useAllData('/Invite/Code', `/Activity/v1.0/Invite/Code`, { id: info.value.gameID }).then(({ data }: { data: any }) => {
    for (let key in data.value.data) {
      Invite[key] = data.value.data[key]
    }
  })
}
// 监听弹窗是否打开
watch(centerDialogVisible, (newval) => {
  if (newval) {
    initData()
    nextTick(() => {
      // loading.value = false;
      let time = setInterval(() => {
        loading.value = false;
        clearInterval(time);
      }, 500);


    });

  }
}, {
  immediate: true
});

let opent = ():void => {
  store.$patch({ terouro: true })
};

const open2 = ():void => {
  ElMessage({
    message: t("language.info.copytips"),
    type: "success",
  });
};
let close = ():void => {
  store.$patch({ terouro: false })
};
let imglist = reactive<{img:string,callback:Function}[]>([
  {
    img: "/img/fly.png",
    callback: (url: string) => { window.open('https://t.me/share/url?url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096&text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL') }
  },
  {
    img: "/img/re9.png",
    callback: (url: string) => { window.open('https://m.facebook.com/') }
  },
  {
    img: "/img/re8.png",
    callback: (url: string) => { window.open('https://api.whatsapp.com/send/?text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL&url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096') }
  },
  {
    img: "/img/re10.png",
    callback: (url: string) => { window.open('https://www.instagram.com/') }
  },
  {
    img: "/img/re7.png",
    callback: (url: string) => { window.open('https://twitter.com/intent/post?text=Crypto Casino | Bitcoin Gambling |Sports Betting Join our-Leading Crypto Casino.Best crypto gambling with 5000+Slots, Dice, Roulette, Blackjack %26 Sports Betting.Enjoy instant withdrawals in BRL&url=https://bc.wg141.com/home?uid=19676882%26t=1714100324096') }
  },

]);
defineExpose({
  opent,
});
</script>

<style lang="scss">
.el-dialog {
  padding: 10px !important;
  background-color: #32353e !important;
  --el-dialog-bg-color: #32353e !important;

  &::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
  }
}

.el-pager li {
  background-color: rgb(26, 26, 26) !important;
  color: #0a906c !important;
}

.el-pagination button {
  background: rgb(26, 26, 26) !important;
}

.el-dialog__header {
  padding: 0 0 0 !important;
}

.closerank {
  width: 100%;
  @include flex(row, space-between, center);
  border-bottom: 1px solid #4a4c53;
  padding-bottom: 15px;
  cursor: pointer;

  strong {
    width: 30px;
    display: block;
  }

  h3 {
    font-size: 18px;
    color: #b5b6c8;
    text-align: center;
    flex: 1;
  }

  span {
    display: block;
    width: 28px;
    height: 28px;
    @include flex(row, center, center);
    border: 2px solid #b5b6c8;
    border-radius: 16px;
  }
}

#Terouro {
  width: 100%;
  height: 100%;
  background: #32353e;
  padding: 0 10px;

  .el-skeleton__image,
  .el-skeleton__text,
  .el-skeleton__h3 {
    background-color: rgb(22, 22, 27);
  }

  main {
    width: 100%;
    margin-top: 20px;
    padding-bottom: 60px;

    >img {
      width: 100%;
      height: 170px;
    }

    ul {
      width: 100%;
      border: 1px solid #4a4c53;
      margin-top: 20px;

      li {
        @include flex(row, space-between, center);

        span {
          font-size: 14px;
          color: #b5bac8;
          text-align: center;
          display: block;
          padding: 10px 8px;
          width: 80%;
          border-right: 1px solid #4a4c53;
        }

        span+span {
          border: none;
          flex: 1;
        }
      }

      li+li {
        border-top: 1px solid #4a4c53;
      }
    }

    .img {
      width: 100%;
      padding: 40px 10px;
      @include flex(row, center, center);

      img {
        width: 43px;
        border-radius: 5px;
      }

      img+img {
        margin-left: 30px;
      }
    }

    h3 {
      text-align: center;
      color: #b5bac8;
      font-size: 18px;
    }

    >dl {
      width: 100%;
      margin-top: 30px;

      dd {
        width: 100%;
        @include flex(row, space-between, center);

        span {
          display: block;
          flex: 1;
          font-size: 14px;
          color: #b5bac8;
          text-align: center;
          word-wrap: break-word;
          margin-right: 10px;
        }

        >div {
          width: 70%;
          height: 50px;
          border: 1px solid #4c4c4f;
          border-radius: 7px;
          @include flex(row, space-between, center);
          padding: 10px 20px;

          span {
            flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-size: 14px;
            color: #b5bac8;
            text-align: left;
          }

          .confirm {
            font-style: normal;
            background-color: #0a906c;

            border-radius: 5px;

            height: 28px;
            padding: 10px;
            border: none;
            font-size: 12px;

            span {
              color: #fff;
            }
          }
        }
      }

      dd+dd {
        margin-top: 20px;
      }
    }
  }
}
</style>
